package com.cxl.parser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Tag;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.HasChildFilter;
import org.htmlparser.filters.HasParentFilter;
import org.htmlparser.filters.TagNameFilter;

public class GrabAmazon extends Grab implements InfoGrab<String> {

	
	
	public NodeFilter getFilter() {
		return   new AndFilter(new TagNameFilter("b"),
				new  HasAttributeFilter("class", "priceLarge"));
		
	}

	public NodeFilter getPictureFilter() {
		// TODO Auto-generated method stub
		return null;
	}

	
	/**
	 * <div class="data">
    <div class="title">div class="data"
<a class="title" span class="text"  <span class="srTitle">
	 */
	public NodeFilter getSearchUrlFiter() {
		NodeFilter filter4 = new AndFilter(new TagNameFilter("span"),
		new HasAttributeFilter("class", "srTitle"));
		return   new AndFilter(new TagNameFilter("a"),
			new HasChildFilter(filter4));
		
		
//return new TagNameFilter("a");
		
//		NodeFilter filter4 = new AndFilter(new TagNameFilter("div"),
//				new HasAttributeFilter("class", "data"));
		
//		NodeFilter filter2 = new AndFilter(new TagNameFilter("div"),
//				new HasParentFilter(filter4));
//		
//		return   new AndFilter(new TagNameFilter("a"),
//				new  HasParentFilter(filter2));
		
		
//		NodeFilter filter4 = new TagNameFilter("div");
//		NodeFilter filter2 = new AndFilter(new TagNameFilter("div"),
//		new HasParentFilter(filter4));
//
//		return   new AndFilter(new TagNameFilter("a"),
//		new  HasParentFilter(filter2));
//		
		//return filter2;
	}				 


//	@Override
//	public String getEncode() {
//		// TODO Auto-generated method stub
//		return "GB2312";
//	}
	
	/**
	 * try {
		Double db =new Double(0);
		String beginkey = null;
		String endKey = null;
		int length = 0;
		
		beginkey = "京东价";
		length = 5;
		endKey = "。";

		HttpClient httpClient = new DefaultHttpClient();
		HttpUriRequest request = new HttpGet(url);
		HttpResponse response;
		
			response = httpClient.execute(request);
		
		HttpEntity entity = response.getEntity();
		String content = EntityUtils.toString(entity);
		int num = content.indexOf(beginkey);
		content = content.substring(num + length);
		num = content.indexOf(endKey);
		return getMoney(content.substring(0, num));
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	 */

	

	
	public NodeFilter getNextFilter() {
		// TODO Auto-generated method stub
		return null;
	}

	//<div class="bucket" id="productDescription">
	public NodeFilter getContentFilter() {
		return   new AndFilter(new TagNameFilter("div"),
				new  HasAttributeFilter("id", "productDescription"));
	}

	public NodeFilter getContentFilter1() {
		// TODO Auto-generated method stub
		return null;
	}

	public NodeFilter getContentFilter2() {
		// TODO Auto-generated method stub
		return null;
	}

	


	public NodeFilter getTitleFilter() {
		NodeFilter filter=new AndFilter(new TagNameFilter("span"),new  HasAttributeFilter("id", "btAsinTitle"));
		return filter;
	}

	public NodeFilter getNotExistsFilter() {
		// TODO Auto-generated method stub
		return null;
	}

	public NodeFilter getBrandFilter() {
		// TODO Auto-generated method stub
		return null;
	}

	

}
